package com.dy.drp.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Auther: dy
 * @Date: 2022/4/1 - 04 - 01 - 17:00
 * @Description: com.dy.drp.config
 * @version: 1.0
 */
public class SysWebMvcConfigurer implements WebMvcConfigurer {
    @Autowired
    private LocationInterceptor locationInterceptor;

    //配置静态资源放行
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //类路径配置
        registry.addResourceHandler("/page/**").addResourceLocations("classpath:/page/");
        //本地磁盘配置
        registry.addResourceHandler("/img/**").addResourceLocations("file:f:/img/");
    }

    //配置跨域访问
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedHeaders("*")
                .allowedMethods("*");
    }

    //配置拦截器 -- > 除登录 注册 注销外拦截所有
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(locationInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login/**")
                .excludePathPatterns("/img/**");
    }
}
